<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@page import="vn.edu.hungvuongaptech.dao.ProjectDAO"%>
<%@page import="vn.edu.hungvuongaptech.dao.StatusDAO"%>
<%@page import="vn.edu.hungvuongaptech.dao.RoleDAO"%>
<%@page import="vn.edu.hungvuongaptech.dao.UserDAO"%>

<%@page import="vn.edu.hungvuongaptech.dao.TimeSheetDAO"%>
<fmt:bundle basename="i18n">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <link rel="stylesheet" href="<%=request.getContextPath()%>/css/general.css" />
            <link rel="stylesheet" href="<%=request.getContextPath()%>/css/aqua.css" />
            <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.3.2.min.js"></script>
            <script type="text/javascript" src="<%=request.getContextPath()%>/js/General.js"></script>
            <script type="text/javascript" src="<%=request.getContextPath()%>/js/zapatec.js"></script>
            <script type="text/javascript" src="<%=request.getContextPath()%>/js/calendar.js"></script>
            <script type="text/javascript" src="<%=request.getContextPath()%>/js/calendar-en.js"></script>
            <title>TimeSheet Approval</title>
        </head>
        <body>
            <div id="main-wrap">
                <!-- S HEAD CONTENT -->
                <jsp:include page="../block/header.jsp" />
                <!-- E HEAD CONTENT -->

                <div class="space"></div>

                <!-- S BODY CONTENT -->
                <div id="body">
                    <div id="center-column">
                        <!-- Dynamic content place here -->
                        <form name="frmSearch" action="FilterTimeSheetController" method="get">
                            <table align="center" cellpadding="4" width="100%">
                                <tr>
                                    <td align="right"><fmt:message key="timesheet.combobox.projectLabel" /></td>
                                    <td><select id="cboProject" name="cboProject">
                                            <option value="">- All -</option>
							<c:set var="projectList" value="<%= ProjectDAO.getAllProject() %>" />
                                            <c:forEach items="${projectList}" var="item">
                                                <c:choose>
                                                    <c:when test="${item.projectId eq param.cboProject}">
                                                        <option value="${ item.projectId }" selected="selected"> ${ item.projectName } </option>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <option value="${ item.projectId }"> ${ item.projectName } </option>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:forEach>
                                        </select></td>
                                    <td align="right"><fmt:message key="timesheet.combobox.statusLabel" /></td>
                                    <td><select id="cboStatus" name="cboStatus">
                                            <option value="">- All -</option>
								<c:set var="statusList" value="<%= StatusDAO.getAllStatuses() %>" />
                                            <c:forEach items="${statusList}" var="item">
                                                <c:choose>
                                                    <c:when test="${item.statusId eq param.cboStatus}">
                                                        <option value="${ item.statusId }" selected="selected"> ${ item.statusName } </option>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <option value="${ item.statusId }"> ${ item.statusName } </option>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:forEach>
                                        </select></td>
                                    <td align="right"><fmt:message key="timesheet.textbox.userLabel" /></td>
                                    <td><select id="cboUser" name="cboUser">
                                            <option value="">- All -</option>
								<c:set var="roleList" value="<%= RoleDAO.getAllRoles() %>" />
                                            <c:forEach items="${roleList}" var="roleItem">
                                                <optgroup label="${ roleItem.roleName }"></optgroup>
                                                <c:set var="roleId" value="${roleItem.roleId}" scope="request" />
									<c:set var="userList" value='<%= UserDAO.getAllUsersByRoleId(Integer.parseInt(request.getAttribute("roleId").toString())) %>' />
                                                <c:forEach items="${userList}" var="item">
                                                    <c:choose>
                                                        <c:when test="${item.userId eq param.cboUser}">
                                                            <option value="${ item.userId }" selected="selected"> ${ item.username } </option>
                                                        </c:when>
                                                        <c:otherwise>
                                                            <option value="${ item.userId }"> ${ item.username } </option>
                                                        </c:otherwise>
                                                    </c:choose>
                                                </c:forEach>
                                            </c:forEach>
                                        </select></td>
                                    <td align="right"><fmt:message key="timesheet.textbox.fromDateLabel" /></td>
                                    <td>
                                        <c:choose>
                                            <c:when test='${param.txtFromDate ne ""}'>
                                                <input type="text" name="txtFromDate" id="txtFromDate" size="10" value="${ param.txtFromDate }" />
                                            </c:when>
                                            <c:otherwise>
                                                <input type="text" name="txtFromDate" id="txtFromDate" size="10" />
                                            </c:otherwise>
                                        </c:choose>
                                        <img id="imgFromDate" src="../images/view_calendar_day.png" alt="Calendar"
                                             height="20px" style="margin-bottom: -5px;" /></td>
                                    <td align="right"><fmt:message key="timesheet.textbox.toDateLabel" /></td>
                                    <td>
                                        <c:choose>
                                            <c:when test='${param.txtToDate ne ""}'>
                                                <input type="text" name="txtToDate" id="txtToDate" size="10" value="${ param.txtToDate }" />
                                            </c:when>
                                            <c:otherwise>
                                                <input type="text" name="txtToDate" id="txtToDate" size="10" />
                                            </c:otherwise>
                                        </c:choose>
                                        <img
                                            id="imgToDate" src="../images/view_calendar_day.png" alt="Calendar"
                                            height="20px" style="margin-bottom: -5px;" /></td>
                                    <td><input type="submit" name="btnSearch" value="<fmt:message key="timesheet.button.searchLabel" />"
                                               class="button" /></td>
                                </tr>
                            </table>
                            <script type="text/javascript">
                                //<![CDATA[
                                Zapatec.Calendar.setup({
                                    firstDay          : 1,
                                    weekNumbers       : false,
                                    range             : [2010.01, 2020.12],
                                    electric          : false,
                                    inputField        : "txtFromDate",
                                    button            : "imgFromDate",
                                    ifFormat          : "%m-%d-%Y"
                                });
                                //]]>
                                //<![CDATA[
                                Zapatec.Calendar.setup({
                                    firstDay          : 1,
                                    weekNumbers       : false,
                                    range             : [2010.01, 2020.12],
                                    electric          : false,
                                    inputField        : "txtToDate",
                                    button            : "imgToDate",
                                    ifFormat          : "%m-%d-%Y"
                                });
                                //]]>
                            </script>
                        </form>

                        <form id="timesheetForm" method="post" action="ApproveTimeSheetController">
                            <input type="button" name="btnExport" class="button" onclick="exportBtnClick('timesheetForm');"
                                   value="<fmt:message key="timesheet.button.exportLabel" />" />
                            <c:set var="timeSheetModels" value="<%= TimeSheetDAO.getTimeSheetByRoleAndStatus(2, 1)%>" />
                            <table width="100%" border="1" cellpadding="2" class="table">
                                <tr>
                                    <th width="15px"> <input type="checkbox" name="chkSelectAll" id="chkSelectAll" alt="Select All" onclick="checkAll(this.name, 'chkTimeSheetID')" /> </th>
                                    <th width="70px"><fmt:message key="timesheet.table.dateLabel" /></th>
                                    <th width="35px"><fmt:message key="timesheet.table.timeLabel" /></th>
                                    <th><fmt:message key="timesheet.table.descriptionLabel" /></th>
                                    <th><fmt:message key="timesheet.table.productLabel" /></th>
                                    <th><fmt:message key="timesheet.table.workLabel" /></th>
                                    <th><fmt:message key="timesheet.table.processLabel" /></th>
                                    <th><fmt:message key="timesheet.table.statusLabel" /></th>
                                    <th><fmt:message key="timesheet.table.projectLabel" /></th>
                                    <th><fmt:message key="timesheet.table.userLabel" /></th>
                                </tr>
                                <c:forEach items="${timeSheetModels}" var="item">
                                    <tr>
                                        <td align="center"> <input type="checkbox" name="chkTimeSheetID" id="chkTimeSheetID" alt="${ item.timeSheetId }" value="${ item.timeSheetId }" /> </td>
                                        <td align="right">${ item.date }</td>
                                        <td align="right">${ item.time }</td>
                                        <td>${ item.description }</td>
                                        <td>${ item.product.productName }</td>
                                        <td>${ item.work.workName }</td>
                                        <td>${ item.process.processName }</td>
                                        <td>${ item.status.statusName }</td>
                                        <td>${ item.project.projectName }</td>
                                        <td align="center">${ item.user.username }</td>
                                    </tr>
                                </c:forEach>
                            </table>
                            <div style="padding: 10px;" align="center">
                                <input type="submit" value="<fmt:message key="timesheet.button.approveLabel" />" name="btnApprove" id="btnApprove" class="button" />
                                &nbsp;&nbsp;
                                <input type="submit" value="<fmt:message key="timesheet.button.rejectLabel" />" name="btnReject" id="btnReject" class="button" />
                            </div>
                        </form>

                        <!-- Dynamic content place here -->
                    </div>
                </div>
                <!-- E BODY CONTENT -->

                <div class="space"></div>

                <!-- S FOOT CONTENT -->
                <jsp:include page="../block/footer.jsp" />
                <!-- E FOOT CONTENT -->
            </div>
        </body>
    </html>
</fmt:bundle>